using System;
using System.Threading;
using CodePlex.DnD4eCampaignManager.DnD4e;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;
using NUnit.Framework;

namespace CodePlex.DnD4eCampaignManager.CampaignManagerTests.DnD4eTests
{
    [TestFixture]
    public class InitiativeTests
    {
        private int _initiativeModifier;
        private int _initiativeRoll;
        private int _initiativeScore;

        [Test]
        public void HasInitiativeModifier()
        {
            IInitiative initiative = new Initiative { InitiativeModifier = _initiativeModifier };
            Assert.AreEqual(_initiativeModifier, initiative.InitiativeModifier);
        }

        [Test]
        public void HasInitiativeRoll()
        {
            IInitiative initiative = new Initiative { InitiativeRoll = _initiativeRoll };
            Assert.AreEqual(_initiativeRoll, initiative.InitiativeRoll);
        }

        [Test]
        public void ImplementsIEquatable()
        {
            Assert.IsInstanceOfType(typeof ( IEquatable<Initiative> ), new Initiative());
        }

        [Test]
        public void ImplementsIInitiative()
        {
            Assert.IsInstanceOfType(typeof ( IInitiative ), new Initiative());
        }

        [Test]
        public void InitiativeRollIsInitializedInConstructorToNumberBetween1And20Inclusive()
        {
            IInitiative initiative;
            for ( int i = 0; i < 100; i++ )
            {
                initiative = new Initiative();
                Console.Out.WriteLine("initiative.InitiativeRoll[{1}] = {0}", initiative.InitiativeRoll, i);
                Assert.LessOrEqual(1, initiative.InitiativeRoll);
                Assert.GreaterOrEqual(20, initiative.InitiativeRoll);
                Thread.Sleep(10);
            }
        }

        [Test]
        public void InitiativeScoreCanBeSetManually()
        {
            IInitiative initiative = new Initiative();
            _initiativeScore = new Random().Next(5, 20);
            initiative.InitiativeScore = _initiativeScore;
            Assert.AreEqual(_initiativeScore, initiative.InitiativeScore);
        }

        [Test]
        public void InitiativeScoreEqualsInitiativeRollPlusInitiativeModifier()
        {
            IInitiative initiative = new Initiative();
            int initiativeScore = initiative.InitiativeRoll + initiative.InitiativeModifier;
            Assert.AreEqual(initiativeScore, initiative.InitiativeScore);
        }

        [SetUp]
        public void SetUp()
        {
            _initiativeModifier = new Random().Next(-5, 10);
            _initiativeRoll = new Random().Next(-5, 10);
            _initiativeScore = new Random().Next(5, 20);
        }
    }
}